<template>
	<view class="indexs">
		<view class="header header_wi" :style="'padding-top: ' + navH + 'px;'">
			<view class="header_height" :style="'height:' + gaodu + 'px;line-height:' + gaodu + 'px;top:' + gaodutops + 'px;'">
				<view class="index_h_cont3">
					<view class="index_wenben_img" @tap="jumpzuo"><image :src="imgUrl + '/dzx_img33.png'" mode="widthFix"></image></view>
					<view class="index_wenben">{{ words.withdraw_list.title.value }}</view>
				</view>
			</view>
			<view class="coloe_title">s</view>
		</view>
		<view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;'">
			<view class="my_tixian_center">
				<view class="my_yue_item1">
					<image :src="imgUrl + '/dzx_img135.png'"></image>
					<view class="my_yue_item1_txt">
						<view class="my_yue_item1_t1">{{ words.withdraw_apply.words.capital.value }}</view>
						<view class="my_yue_item1_dis">
							<view class="my_yue_item1_t2">{{ dealer['money'] }}</view>
							<view @tap="jump_txmingxi" class="my_yue_item1_t3">{{ words.withdraw_list.title.value }}</view>
						</view>
					</view>
				</view>
				<view class="my_tixian_item2">
					<view class="my_tixian_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ words.withdraw_apply.words.money.value }}</text>
					</view>
					<view class="my_tixian_item2_dis">
						<input type="number" @input="inputMoney" :value="money" :placeholder="words.withdraw_apply.words.money_placeholder.value" />
						<view class="my_tixian_item2_t1" @tap="all">{{ $t('page_my_tixian.Full_withdrawal') }}</view>
					</view>
					<view class="xuzhi">{{ $t('page_my_tixian.zhu') }}：{{ words.withdraw_apply.words.min_money.value }}: {{ settlement.min_money }}</view>
				</view>
				<view class="form-item">
					 <view class="form-label">
					 	  {{ $t('page_my_tixian.tixianzhi') }}
					 </view>
					 <view class="form-content">
						 <picker @change="bindTypePickerChange" :range="paytypestatus">
							 <text>{{ paytypeEnum[type] }} 【{{ $t('page_my_tixian.dianjiqiehuan') }}】</text>
						 </picker>
					 </view>
				</view>
				<view class="form-group" v-if="type==20">
					 <view class="form-item">
						<text class="tips-label">{{ $t('page_my_tixian.xingming') }}</text> 
				       <input type="text" @input="input" data-field="alipay_name" :placeholder="$t('page_my_tixian.xingmingremark')" value="" />				 	
					</view>
					 <view class="form-item">
						 <text class="tips-label">{{ $t('page_my_tixian.zhifubao') }}</text>
						<input type="text" @input="input" data-field="alipay_account" :placeholder="$t('page_my_tixian.zhifubaoremark')" value="" />			 	
					 </view> 
				</view>
				<view class="form-group" v-if="type==30">
					 <view class="form-item">
						<text class="tips-label">{{ $t('page_my_tixian.xingming') }}</text> 
						<input type="text" @input="input" data-field="bank_name" :placeholder="$t('page_my_tixian.xingmingremark')" value="" />				 	
					 </view>
					 <view class="form-item">
						 <text class="tips-label">{{ $t('page_my_tixian.bank_account') }}</text>
						<input type="text" @input="input" data-field="bank_account" :placeholder="$t('page_my_tixian.bank_account')" value="" />			 	
					 </view>
					 <view class="form-item">
							<text class="tips-label">{{ $t('page_my_tixian.bank_card') }}</text>
							<input type="text" @input="input" data-field="bank_card" :placeholder="$t('page_my_tixian.bank_cardremark')" value="" />			 	
					 </view> 
				</view>
				<view class="my_tixian_item3">
					<view class="my_tixian_item3_btns" @tap="toSubmit">{{ words.withdraw_apply.words.submit.value }}</view>
				</view>
				<view class="my_tixian_item4">
					<view class="my_tixian_item2_title">
						<image :src="imgUrl + '/dzx_img47.png'"></image>
						<text>{{ $t('page_my_tixian.Withdrawal_instructions') }}</text>
					</view>
					<view class="my_tixian_item4_list">
						<view class="my_tixian_item4_cont">{{ words.withdraw_apply.words.xieyi.value }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
// pages/shouye/shouye_zkc/shouye_zkc.js
const app = getApp();
let request = require('../../../utils/require');
export default {
	data() {
		return {
			navH: app.globalData.navHeight,
			gaodu: app.globalData.height,
			imgUrl: app.globalData.imgUrl,
			gaodutops: app.globalData.top,
			dealer: [],
			words: [],
			settlement: [],
			money: 0,
			type: 0 , 
			submsgSetting: [],
			paytypeEnum:[],
			formData:[],
			paytypestatus:[],
		};
	},
	/**
	 * 生命周期函数--监听页面加载
	 */ 
	onLoad() {
		var that = this;
		that.getSubmsgSetting();
	},
	onShow() {
		var that = this;
		that.getDealerData();
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {},
	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {},
	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {},
	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {},
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {},
	methods: {
		input(e){
			 var field = e.currentTarget.dataset.field;
			 this.formData[field] = e.detail.value; 
		},
		bindTypePickerChange(e){
			console.log(e,788656);
			this.type = this.settlement.pay_type[e.detail.value];
		},
		jumpzuo() {
			uni.navigateBack();
		},
		jump_txmingxi() {
			uni.navigateTo({
				url: '/pages/mys/my_tixianmx/my_tixianmx'
			});
		},
		toSubmit() {
			var a = Number(this.dealer['money']);
			if (this.money <= 0) {
				uni.showToast({
					icon: 'none',
					title: '请输入金额'
				});
				return;
			}
			if (this.money > a) {
				uni.showToast({
					icon: 'none',
					title: '你输入的金额大于可提现余额'
				});
				return;
			}
			
			var data = {
				token: uni.getStorageSync('token'),
				pay_type:this.type,
				money: this.money
			};
			switch(data.pay_type){
				case '10':
				  break;
				case '20':
				  data['alipay_name'] = this.formData['alipay_name'];
				  data['alipay_account'] = this.formData['alipay_account'];
				  break;
				case '30':
				  data['bank_name'] = this.formData['bank_name'];
				  data['bank_account'] = this.formData['bank_account'];
				  data['bank_card'] = this.formData['bank_card'];
				  break;
				case '40':
				  break;
			}
			console.log(data,78765)
			request.post(`index.php?s=/api/user.dealer.withdraw/submit&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					uni.showToast({
						title: '提现申请成功'
					});
					//发起订阅消息
					this.onRequestSubscribeMessage();
				}else{
					uni.showToast({
						title: res.data.msg
					});
				}
				
			});
		},
		inputMoney(e) {
			var value = e.detail.value;
			this.money= value
		},
		/**
		 * 订阅消息 => [提现通知]
		 */
		onRequestSubscribeMessage() {
			var that = this,
				tmplIds = [],
				dealerSubmsg = that.submsgSetting.dealer;
			dealerSubmsg.withdraw_01.template_id != '' && tmplIds.push(dealerSubmsg.withdraw_01.template_id);
			dealerSubmsg.withdraw_02.template_id != '' && tmplIds.push(dealerSubmsg.withdraw_02.template_id);
			if (tmplIds.length > 0) {
				wx.requestSubscribeMessage({
					tmplIds,
					success(res) {
						setTimeout(function() {
							uni.navigateTo({
								url: '../my_fenxiao/my_fenxiao'
							});
						}, 1000);
					},
					fail(res) {
						setTimeout(function() {
							uni.navigateTo({
								url: '../my_fenxiao/my_fenxiao'
							});
						}, 1000);
					},
					complete(res) {
						setTimeout(function() {
							uni.navigateTo({
								url: '../my_fenxiao/my_fenxiao'
							});
						}, 1000);
					}
				});
			}
		},
		all() {
			this.money= this.dealer['money']
		},
		getSubmsgSetting() {
			var that = this;
			var data = {
				token: uni.getStorageSync('token')
			};
			request.get(`index.php?s=/api/wxapp.submsg/setting&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				console.log(res.data.data.setting, 778877);
				that.submsgSetting= res.data.data.setting
			});
		},
		getDealerData() {
			var that = this;
			var data = {
				token: uni.getStorageSync('token')
			};
			request.get(`index.php?s=/api/user.dealer/withdraw&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					this.dealer = res.data.data.dealer;
					this.words = res.data.data.words;
					this.settlement = res.data.data.settlement;
					this.type = res.data.data.settlement.pay_type[0];
					this.paytypeEnum = res.data.data.payenum;
					for (var i = 0; i < res.data.data.settlement.pay_type.length; i++) {
						this.paytypestatus[i] = res.data.data.payenum[res.data.data.settlement.pay_type[i]];
					}
					console.log(this.paytypestatus,8766)
				}
			});
		}
	}
};
</script>
<style>
@import './my_tixian.css';
</style>
